<?

class Mojito_Controller_Action_Helper_Images extends Zend_Controller_Action_Helper_Abstract
{
	/**
	 * thumbnail function.
	 * $args = array (
		 'source'=> the file to open
		 'format'=>format to set output to (png. jpg,gif, etc...)
		 'width'=>int in pixels
		 'height'=>int in pixels
		 'square'=>boolean, true for cropping rectangles images
		 'target'=>full path and filename of where to save the image
		 )
	 * 
	 * @access public
	 * @static
	 * @param mixed array $args
	 * @return void
	 */
	public static function thumbnail(array $args)
	{
		$Image = new Imagick();
		$Image->setResolution(72,72);
		$Image->readImage($args['source']);
		$Image->setImageFormat(($args['format']?$args['format']:'png'));
		
	
		/* Thumbnail the image */
		$Image->thumbnailImage($args['width'],($args['height']?$args['height']:null));
		if ($args['square']) $Image->cropImage($args['width'],$args['width'],0,0);
				
		/* Save the image*/
		$Image->writeImage($args['target']);
	}

}